<?php
//Nguyen Van Binh
//suongmumc@gmail.com

defined( '_VALID_NVB' ) or die( 'Direct Access to this location is not allowed.' );
function Get_Main_Id_Menu($id){
	global $DB,$lang;
	$id=intval($id);
	$sql="SELECT * FROM menu".$lang." WHERE id_menu=$id";
	$db=$DB->query($sql);
	$idmain=$id;
	if($rs=mysql_fetch_array($db)){
		$sql1="SELECT * FROM menu".$lang." WHERE id_menu=$rs[parentid]"	;
		$db1=$DB->query($sql1);
		if($rs1=mysql_fetch_array($db1)){
			$idmain=Get_Main_Id_Menu($rs1['id_menu']);
		}
	}
	return $idmain;
}

function Get_Id_Cat($idc){
	global $DB,$lang;
	$idc=intval($idc);
	$list_id.=$idc;
	$sql="SELECT * FROM cat".$lang." WHERE active=1 AND parentid=$idc";
	$db=$DB->query($sql);
	while($rs=mysql_fetch_array($db)){
		$list_id.=",".Get_Id_Cat($rs['id_cat']);	
	}
	return $list_id;
}	
function Get_Id_CatPT($idc){
	global $DB,$lang;
	$idc=intval($idc);
	$list_id.=$idc;
	$sql="SELECT * FROM catpt".$lang." WHERE active=1 AND parentid=$idc";
	$db=$DB->query($sql);
	while($rs=mysql_fetch_array($db)){
		$list_id.=",".Get_Id_Cat($rs['id_catpt']);	
	}
	return $list_id;
}	

function Get_Id_CatPD($idc){
	global $DB,$lang;
	$idc=intval($idc);
	$list_id.=$idc;
	$sql="SELECT * FROM catpd".$lang." WHERE active=1 AND parentid=$idc";
	$db=$DB->query($sql);
	while($rs=mysql_fetch_array($db)){
		$list_id.=",".Get_Id_Cat($rs['id_catpd']);	
	}
	return $list_id;
}
function Get_Id_CatVD($idc){
	global $DB,$lang;
	$idc=intval($idc);
	$list_id.=$idc;
	$sql="SELECT * FROM catvideo".$lang." WHERE active=1 AND parentid=$idc";
	$db=$DB->query($sql);
	while($rs=mysql_fetch_array($db)){
		$list_id.=",".Get_Id_CatVD($rs['id_catvideo']);	
	}
	return $list_id;
}	

function Get_Id_CatLG($idc){
	global $DB,$lang;
	$idc=intval($idc);
	$list_id.=$idc;
	$sql="SELECT * FROM catlg".$lang." WHERE active=1 AND parentid=$idc";
	$db=$DB->query($sql);
	while($rs=mysql_fetch_array($db)){
		$list_id.=",".Get_Id_CatLG($rs['id_catlg']);	
	}
	return $list_id;
}	

function Get_Main_Cat_Name($idc){
	global $DB,$lang;
	$idc=intval($idc);
	$str="";
	$sql="SELECT * FROM cat".$lang." WHERE active=1 AND id_cat=$idc";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$str=clean_url($rs['name'])."/";
		$sql1="SELECT * FROM cat".$lang." WHERE active=1 AND id_cat=$rs[parentid]";
		$db1=$DB->query($sql1);
		
		if($rs1=mysql_fetch_array($db1)){
			$str=Get_Main_Cat_Name($rs1['id_cat']).$str	;
		}
	}
	return $str;
}
function Get_Main_CatPD_Name($idc){
	global $DB,$lang,$site_address;
	$idc=intval($idc);
	$str="";
	$sql="SELECT * FROM catpd".$lang." WHERE active=1 AND id_catpd=$idc";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$str=clean_url($rs['name'])."/";
		$sql1="SELECT * FROM catpd".$lang." WHERE active=1 AND id_catpd=$rs[parentid]";
		$db1=$DB->query($sql1);
		
		if($rs1=mysql_fetch_array($db1)){
			$str=Get_Main_CatPD_Name($rs1['id_catpd']).$str	;
		}
	}
	return $str;
}

function Get_Main_Catpt_Name($idc){
	global $DB,$lang;
	$idc=intval($idc);
	$str="";
	$sql="SELECT * FROM catpt".$lang." WHERE active=1 AND id_catpt=$idc";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$str=clean_url($rs['name'])."/";
		$sql1="SELECT * FROM catpt".$lang." WHERE active=1 AND id_catpt=$rs[parentid]";
		$db1=$DB->query($sql1);
		
		if($rs1=mysql_fetch_array($db1)){
			$str=Get_Main_Catpt_Name($rs1['id_catpt']).$str	;
		}
	}
	return $str;
}

function Get_Main_Cat_Name_path($idc){
	global $DB, $site_address,$lang, $lang_dir,$idmenu;
	$idc=intval($idc);
	$sql="SELECT * FROM cat".$lang." WHERE active=1 AND id_cat=$idc";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$str="<a href='".$site_address.$rs['url']."'>".$rs['name']."</a>";
		$sql1="SELECT * FROM cat".$lang." WHERE id_cat=$rs[parentid]";
		$db1=$DB->query($sql1);
		if($rs1=mysql_fetch_array($db1)){
			$str=Get_Main_Cat_Name_path($rs1['id_cat'])."&nbsp;>&nbsp;".$str;
		}
	}
	return $str;
}
function Get_Main_Catpt_Name_path($idc){
	global $DB, $site_address,$lang, $lang_dir,$idmenu;
	$idc=intval($idc);
	$sql="SELECT * FROM catpt".$lang." WHERE active=1 AND id_catpt=$idc";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$str=$rs['name'];
	}
	return $str;
}

function Get_Cat_Name($table,$id_cat,$idc){
	global $DB, $site_address,$lang, $lang_dir,$idmenu;
	$idc=intval($idc);
	$sql="SELECT * FROM ".$table.$lang." WHERE active=1 AND ".$id_cat."=$idc";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$str=$rs['name'];
	}
	return $str;
}


function Get_Main_CatPD_Name_path($idc){
	global $DB, $site_address,$lang, $lang_dir,$idmenu;
	$idc=intval($idc);
	$sql="SELECT * FROM catpd".$lang." WHERE active=1 AND id_catpd=$idc";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$str="<a href='".$site_address.$rs['url']."'>".$rs['name']."</a>";
		$sql1="SELECT * FROM catpd".$lang." WHERE id_catpd=$rs[parentid]";
		$db1=$DB->query($sql1);
		if($rs1=mysql_fetch_array($db1)){
			$str=Get_Main_CatPD_Name_path($rs1['id_catpd'])."&nbsp;>&nbsp;".$str;
		}
	}
	return $str;
}




function Get_Id_CatIf($idc){
	global $DB,$lang,$lang_dir;
	$idc=intval($idc);
	$list_id.=$idc;
	$sql="SELECT * FROM catif".$lang." WHERE active=1 AND parentid=$idc";
	$db=$DB->query($sql);
	while($rs=mysql_fetch_array($db)){
		$list_id.=",".Get_Id_CatIf($rs['id_catif']);	
	}
	return $list_id;
}	
function Get_Main_CatIf_Name($idc){
	global $DB,$lang;
	$idc=intval($idc);
	$str="";
	$sql="SELECT * FROM catif".$lang." WHERE active=1 AND id_catif=$idc";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$str=clean_url($rs['name'])."/";
		$sql1="SELECT * FROM catif".$lang." WHERE active=1 AND id_catif=$rs[parentid]";
		$db1=$DB->query($sql1);
		
		if($rs1=mysql_fetch_array($db1)){
			$str=Get_Main_CatIf_Name($rs1['id_catif']).$str	;
		}
	}
	return $str;
}
function Get_Main_Catif_Name_path($idc){
	global $DB, $site_address,$lang, $lang_dir,$idmenu;
	$idc=intval($idc);
	
	$sql="SELECT * FROM catif".$lang." WHERE active=1 AND id_catif=$idc";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$catname=Get_Main_CatIf_Name($rs['id_catpd']);
		$pathy=strlen($catname);
		$pathx=substr($catname,0,$pathy-1);
		$str="<a href='".$site_address.$lang_dir.$pathx."_".$rs['id_catif']."_".$idmenu.".td'>".$rs['name']."</a>";
		$sql1="SELECT * FROM catif".$lang." WHERE active=1 AND id_catif=$rs[parentid]";
		$db1=$DB->query($sql1);
		if($rs1=mysql_fetch_array($db1)){
			$str=Get_Main_Catif_Name_path($rs1['id_catif'])."&nbsp;>&nbsp;".$str	;
		}
	}
	return $str;
}

function Get_Link_Menu($idmenu){
	global $DB;
	$id=intval($idmenu);
	$sql="SELECT * FROM menu WHERE id_menu=$id"	;
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		return $rs['link_write'];	
	}
}
?>